﻿'Copyright © Etheral Studios 2012
'File created by Nick nick@etheralstudios.com
'File has been edited by:
'Nick nick@etheralstudios.com

Public Class SMS

    Dim Address As String = MainForm.Address

    Private Sub SMS_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        IP.Text = Address
    End Sub

    Private Sub SMS_FormClosed(sender As System.Object, e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        MainForm.Show()
    End Sub

    Private Sub SendButton_Click(sender As System.Object, e As System.EventArgs) Handles SendButton.Click
        Dim message As String = "1.0.1.0_NT\sms/plaintext\" + MainForm.MyIP + "\" + Address + "\" + Send.Text

        If My.Computer.FileSystem.DirectoryExists("C:\ProgramData\WiN\Server\htdocs\WiN\SMS\" + Address) Then
            If My.Computer.FileSystem.FileExists("C:\ProgramData\WiN\Server\htdocs\WiN\SMS\" + Address + "\ptmsg.wmsg") Then
                Dim myStreamWriter As System.IO.StreamWriter
                myStreamWriter = System.IO.File.CreateText("C:\ProgramData\WiN\Server\htdocs\WiN\SMS\" + Address + "\ptmsg.wmsg")
                myStreamWriter.Write(message)
                myStreamWriter.Flush()
                myStreamWriter.Dispose()

            Else
                Dim myStreamWriter As System.IO.StreamWriter
                myStreamWriter = System.IO.File.CreateText("C:\ProgramData\WiN\Server\htdocs\WiN\SMS\" + Address + "\ptmsg.wmsg")
                myStreamWriter.Write(message)
                myStreamWriter.Flush()
                myStreamWriter.Dispose()
            End If
        Else
            My.Computer.FileSystem.CreateDirectory("C:\ProgramData\WiN\Server\htdocs\WiN\SMS\" + Address)
            Dim myStreamWriter As System.IO.StreamWriter
            myStreamWriter = System.IO.File.CreateText("C:\ProgramData\WiN\Server\htdocs\WiN\SMS\" + Address + "\ptmsg.wmsg")
            myStreamWriter.Write(message)
            myStreamWriter.Flush()
            myStreamWriter.Dispose()
        End If
        Send.Clear()
    End Sub

    Private Sub Timer_Tick(sender As System.Object, e As System.EventArgs) Handles Timer.Tick
        If My.Computer.FileSystem.DirectoryExists("C:\ProgramData\WiN\SMS\" + Address) Then
            My.Computer.FileSystem.DeleteDirectory("C:\ProgramData\WiN\SMS\" + Address, FileIO.DeleteDirectoryOption.DeleteAllContents)
            My.Computer.FileSystem.CreateDirectory("C:\ProgramData\WiN\SMS\" + Address)
            Try
                My.Computer.Network.DownloadFile("http://" + Address + "/WiN/SMS/" + MainForm.MyIP + "/ptmsg.wmsg", "C:\ProgramData\WiN\SMS\" + Address + "\ptmsg.wmsg")
                Dim wmsg_read() As String = IO.File.ReadAllLines("C:\ProgramData\WiN\SMS\" + Address + "\ptmsg.wmsg")
                Dim firstLine As String = wmsg_read(0)
                Dim data() As String = firstLine.Split("\")
                Recive.Text = data(4)
            Catch ex As Exception
                Recive.Text = Address + " is not online."
            End Try
        Else
            My.Computer.FileSystem.CreateDirectory("C:\ProgramData\WiN\SMS\" + Address)
            Try
                My.Computer.Network.DownloadFile("http://" + Address + "/WiN/SMS/" + MainForm.MyIP + "/ptmsg.wmsg", "C:\ProgramData\WiN\SMS\" + Address + "\ptmsg.wmsg")
                Dim src_read() As String = IO.File.ReadAllLines("C:\ProgramData\WiN\SMS\" + Address + "\ptmsg.wmsg")
                Dim firstLine As String = src_read(0)
                Dim data() As String = firstLine.Split("\")
                Recive.Text = data(4)
            Catch ex As Exception
                Recive.Text = Address + " is not online."
            End Try
        End If
    End Sub
End Class